home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / os / sprite / RCS / mitauth.c,v < prev    next >
Encoding:
Text File  |  1992-01-24  |  3.1 KB  |  163 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    stolcke:1.1; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     90.02.14.19.25.20;  author tve;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @Original X11R4 distribution
  17. @
  18.  
  19.  
  20.  
  21. 1.1
  22. log
  23. @Initial revision
  24. @
  25. text
  26. @/*
  27.  * MIT-MAGIC-COOKIE-1 authorization scheme
  28.  *
  29.  * $XConsortium: mitauth.c,v 1.3 89/03/14 15:53:36 rws Exp $
  30.  *
  31.  * Copyright 1988 Massachusetts Institute of Technology
  32.  *
  33.  * Permission to use, copy, modify, and distribute this software and its
  34.  * documentation for any purpose and without fee is hereby granted, provided
  35.  * that the above copyright notice appear in all copies and that both that
  36.  * copyright notice and this permission notice appear in supporting
  37.  * documentation, and that the name of M.I.T. not be used in advertising or
  38.  * publicity pertaining to distribution of the software without specific,
  39.  * written prior permission.  M.I.T. makes no representations about the
  40.  * suitability of this software for any purpose.  It is provided "as is"
  41.  * without express or implied warranty.
  42.  *
  43.  * Author:  Keith Packard, MIT X Consortium
  44.  */
  45.  
  46. #include "X.h"
  47. #include "os.h"
  48.  
  49. static struct auth {
  50.     struct auth    *next;
  51.     unsigned short    len;
  52.     char    *data;
  53.     XID        id;
  54. } *mit_auth;
  55.  
  56. int
  57. MitAddCookie (data_length, data, id)
  58. unsigned short    data_length;
  59. char    *data;
  60. XID    id;
  61. {
  62.     struct auth    *new;
  63.  
  64.     new = (struct auth *) xalloc (sizeof (struct auth));
  65.     if (!new)
  66.     return 0;
  67.     new->data = (char *) xalloc ((unsigned) data_length);
  68.     if (!new->data) {
  69.     xfree(new);
  70.     return 0;
  71.     }
  72.     new->next = mit_auth;
  73.     mit_auth = new;
  74.     bcopy (data, new->data, (int) data_length);
  75.     new->len = data_length;
  76.     new->id = id;
  77.     return 1;
  78. }
  79.  
  80. XID
  81. MitCheckCookie (data_length, data)
  82. unsigned short    data_length;
  83. char    *data;
  84. {
  85.     struct auth    *auth;
  86.  
  87.     for (auth = mit_auth; auth; auth=auth->next) {
  88.         if (data_length == auth->len &&
  89.        bcmp (data, auth->data, (int) data_length) == 0)
  90.         return auth->id;
  91.     }
  92.     return (XID) -1;
  93. }
  94.  
  95. int
  96. MitResetCookie ()
  97. {
  98.     struct auth    *auth, *next;
  99.  
  100.     for (auth = mit_auth; auth; auth=next) {
  101.     next = auth->next;
  102.     xfree (auth->data);
  103.     xfree (auth);
  104.     }
  105.     mit_auth = 0;
  106. }
  107.  
  108. XID
  109. MitToID (data_length, data)
  110. unsigned short    data_length;
  111. char    *data;
  112. {
  113.     struct auth    *auth;
  114.  
  115.     for (auth = mit_auth; auth; auth=auth->next) {
  116.     if (data_length == auth->len &&
  117.         bcmp (data, auth->data, data_length) == 0)
  118.         return auth->id;
  119.     }
  120.     return (XID) -1;
  121. }
  122.  
  123. MitFromID (id, data_lenp, datap)
  124. XID id;
  125. unsigned short    *data_lenp;
  126. char    **datap;
  127. {
  128.     struct auth    *auth;
  129.  
  130.     for (auth = mit_auth; auth; auth=auth->next) {
  131.     if (id == auth->id) {
  132.         *data_lenp = auth->len;
  133.         *datap = auth->data;
  134.         return 1;
  135.     }
  136.     }
  137.     return 0;
  138. }
  139.  
  140. MitRemoveCookie (data_length, data)
  141. unsigned short    data_length;
  142. char    *data;
  143. {
  144.     struct auth    *auth, *prev;
  145.  
  146.     prev = 0;
  147.     for (auth = mit_auth; auth; auth=auth->next) {
  148.     if (data_length == auth->len &&
  149.         bcmp (data, auth->data, data_length) == 0)
  150.      {
  151.         if (prev)
  152.         prev->next = auth->next;
  153.         else
  154.         mit_auth = auth->next;
  155.         xfree (auth->data);
  156.         xfree (auth);
  157.         return 1;
  158.     }
  159.     }
  160.     return 0;
  161. }
  162. @
  163.